<?php

namespace App\Model\Rbac;

use App\Model\CrudModel;

/**
 * @property int $id
 * @property string $name
 */
class RoleModel extends CrudModel
{

    protected bool $softDel = true;

    // 角色
    protected ?string $table = 'role';

//    public function buildQuery(array $params = [])
//    {
//        $where = [];
//        if (!empty($params['name'])){
//            $where[] = ['name',$params['name']];
//        }
//        return $this->autoSearch($params)->where($where);
//    }

    public function addOne(array $data)
    {
        $now = time();
        return $this->insert([
            'deleted_at' => 0,
            'name' => $data['name'],
            'created_at' => $now,
            'updated_at' => $now,
        ]);
    }

    public function findByName($name)
    {
        return $this->buildQuery(['name'=>$name])->first();
    }

    public function updateById($id, array $data)
    {
    }

    public function updateName($id, $name)
    {
        return $this->updateField(['id'=>$id,],'name',$name);
    }

}